% TEST_ID: LANG-EXPAND-0095
% CATEGORY: stdlib/arithmetic_ops/accumulate
% 测试 cummin 函数

function test_cummin()
% 向量中的累积最小值
v = [9    10     2    10     7     1     3     6    10    10];
M = cummin(v);
result = [9     9     2     2     2     1     1     1     1     1];
assert(M == result);

% 矩阵列中的累积最小值
A = [3 5 2; 1 6 3; 7 8 1];
M = cummin(A);
result = [3     5     2
    1     5     2
    1     5     1];
assert(M == result);

% 矩阵行中的累积最小值
A = [3 5 2; 1 6 3; 7 8 1];
M = cummin(A,2);
result = [3     3     2
    1     1     1
    7     7     1];
assert(M == result);

% 反向累积最小值
A = cat(3,[1 2; 3 4],[9 10; 11 12],[5 6; 7 8]);
M = cummin(A,3,'reverse');
result = zeros(2,2,3);
result(:,:,1) = [1    2
    3    4];
result(:,:,2) = [5    6
    7    8];
result(:,:,3) = [5     6
    7     8];
assert(M == result);

% 包括缺失值的累积最小值
A = [3 5 NaN 4; 2 6 2 9; 1 3 0 NaN];
M = cummin(A,'includenan')
result = [3     5   NaN     4
    2     5   NaN     4
    1     3   NaN   NaN]
assert(isequaln(M, result));

% 对于缺失值和正常数字的比较
A = [NaN, 3; 4 NaN]
M = cummin(A)
result = [NaN     3
    4     3]
assert(isequaln(M, result))

B = [NaN, 1 + i; 2 + i NaN];
M = cummin(B);
result = [NaN + 0.0000i   1.0000 + 1.0000i
    2.0000 + 1.0000i   1.0000 + 1.0000i];
assert(isequaln(M, result));

% 对空数组进行cummin;
A = ones(0, 3, 2);
assert(size(cummin(A)) == [0 3 2]);
assert(size(cummin(A, 1)) == [0 3 2]);
assert(size(cummin(A, 2)) == [0 3 2]);
assert(size(cummin(A, 3)) == [0 3 2]);

end